package org.tech4j.edi.base.config;

import org.tech4j.common.concurrent.threadpool.MemoryLimitCalculator;

/**
 * @program: tech4j
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/7 15:47
 **/
public class RetryPoolConfig {
    /**
     * Whether to enable shared thread pool, defaults to false.
     * Note: it is planned to be enabled by default when all RPC/HTTP
     * plugins support this shared thread pool.
     */
    private Boolean enable = Boolean.FALSE;

    /**
     * The the thread name prefix, defaults to tech4j-edi-retry.
     */
    private String prefix = "tech4j-edi-retry";

    /**
     * the number of threads to keep in the thread pool.
     */
    private Integer corePoolSize = 200;

    /**
     * the maximum number of threads to allow in the thread pool.
     */
    private Integer maximumPoolSize = Integer.MAX_VALUE;

    /**
     * when the number of threads is greater than the core,
     * this is the maximum time that excess idle threads
     * will wait for new tasks before terminating.
     * Note: the unit of time is {@link java.util.concurrent.TimeUnit#MILLISECONDS}
     */
    private Long keepAliveTime = 60000L;

    /**
     * Maximum memory allowed to be used by a blocking queue, yes, unlike other
     * implementations of {@link java.util.concurrent.BlockingQueue}
     * (which all control memory based on the length of the blocking queue),
     * {@link org.tech4j.common.concurrent.threadpool.MemoryLimitedLinkedBlockingQueue}
     * controls memory directly by calculating the memory size used by the blocking queue.
     */
    private Long maxWorkQueueMemory = MemoryLimitCalculator.defaultLimit();

    /**
     * The memory used by the blocking queue is always in the safe range, and there
     * is always an attempt to make the JVM's free memory higher than this value.
     *
     * @see org.tech4j.common.concurrent.threadpool.MemorySafeLinkedBlockingQueue#getMaxFreeMemory()
     */
    private Integer maxFreeMemory;

    public Boolean getEnable() {
        return enable;
    }

    public void setEnable(Boolean enable) {
        this.enable = enable;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public Integer getCorePoolSize() {
        return corePoolSize;
    }

    public void setCorePoolSize(Integer corePoolSize) {
        this.corePoolSize = corePoolSize;
    }

    public Integer getMaximumPoolSize() {
        return maximumPoolSize;
    }

    public void setMaximumPoolSize(Integer maximumPoolSize) {
        this.maximumPoolSize = maximumPoolSize;
    }

    public Long getKeepAliveTime() {
        return keepAliveTime;
    }

    public void setKeepAliveTime(Long keepAliveTime) {
        this.keepAliveTime = keepAliveTime;
    }

    public Long getMaxWorkQueueMemory() {
        return maxWorkQueueMemory;
    }

    public void setMaxWorkQueueMemory(Long maxWorkQueueMemory) {
        this.maxWorkQueueMemory = maxWorkQueueMemory;
    }

    public Integer getMaxFreeMemory() {
        return maxFreeMemory;
    }

    public void setMaxFreeMemory(Integer maxFreeMemory) {
        this.maxFreeMemory = maxFreeMemory;
    }

}
